﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Collector
{
    public class AppEvent
    {
        #region property

        #endregion

        #region field
        private static Dictionary<object, EventHandler<AppEventArgs>> _eventMap = new Dictionary<object, EventHandler<AppEventArgs>>();
        #endregion
        public static readonly AppEvent Instance = new AppEvent();
        public static void RegistEvent(object obj, EventHandler<AppEventArgs> target)
        {
            if (!_eventMap.ContainsKey(obj))
            {
                _eventMap.Add(obj, new EventHandler<AppEventArgs>(target));
            }
            else
            {
                _eventMap[obj] += target;
            }
        }

        public static void CallEvent(object sender, AppEventArgs e)
        {
            if (_eventMap.ContainsKey(e.Id))
            {
                _eventMap[e.Id](sender, e);
            }
        }
    }
}
